package com.myiam.idm.core.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Role {
	
	
	private long id;
	private String name;
	private String type;
	private Role parent; 
	private List<Role> children;
	
	private List<RoleAttribute> roleAttributes;
	
	private List<RoleConstraint> roleConstraint;
	
	
	/*
	 * management attributes
	 */
	private List<Role> authorizedManagers;
	
	public Role(long id , String name , String type, Role parent) {
		this.id = id;
		this.name=name;
		this.type=type;
		this.parent=parent;
		children= new ArrayList<Role>();
		if (parent !=null) {
			parent.addChild(this);
		}
	}

	public void addChild(Role childRole) {
		children.add(childRole);
	}
	
	public boolean hasChildren() {
		if (children.size()>0) {
			return true;
		}
		return false;
	}
	
	public Iterator<Role> getChildrenAsIterator () {
		return children.iterator();
	}
	
	
	
	
	/*
	 * simpele getters and setters
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public long getId() {
		return id;
	}
	
	
	public Role getParent() {
		return parent;
	}

	public void setParent(Role parent) {
		this.parent = parent;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return getId() + " " + getName();
	}
	
	
}
	